<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

require_once 'page.php';
/**
 * @author Garry Willits
 * @copyright 
 * @date 30th April 2011
 */
class edit  extends page  {
	/**
	* $Id: site.php 55 2012-04-16 20:20:17Z garry.willits@gmail.com $
	* 
	* $Author: garry.willits@gmail.com $
	*
	* $Revision: 55 $
	*
	* $LastChangedDate: 2012-04-16 21:20:17 +0100 (Mon, 16 Apr 2012) $
	*
	* $Copyright$
	//TODO - Insert your code here
	/**
	 * 
	 * Create a content editor
	 */
	public function createContent($contentid) 
	{
		parent::__construct();
		$this->load->helper(array('form', 'url'));
		session_start();
		$contentSelector = "";
		$getContentId = Request::prop('contentId');
		if( !empty($getContentId)   ){
			$contentid = $getContentId;
		}
		$postSelector = Request::prop('content_editor_type');
		if( !empty($postSelector)   ){
			$contentSelector = Request::prop('content_editor_type');
		}
		$getSelector = Request::prop('contentType');
		if( !empty($getSelector)   ){
			$contentSelector = $getSelector;
		}
		$controller = ContentLineManager::GetController($contentSelector);
		$display = $controller->create($contentid);
		parent::addChild($display,'main');
		parent::output(  );
	}
	
	/**
	 * 
	 * Create a content editor
	 */
	public function editContent($id)
	{
		parent::__construct();
		$this->load->helper(array('form', 'url'));
		session_start();
		$controller = ContentLineManager::GetController( Request::prop('contentType') );
		$altID = Request::prop('daoId');
		if( !empty( $altID )   ){
			$id = $altID;
		}
		$display = $controller->edit( $id );
		parent::addChild($display,'main');
		parent::output(  );
	}
	
	/**
	 * 
	 * Create a cotent editor
	 */
	public function deleteContent($id)
	{
		parent::__construct();
		$this->load->helper(array('form', 'url'));
		session_start();
		$sectiondao = ContentLineManager::GetContentDao( Request::prop( 'content_id' ) );
		// bye bye section
		$condemned = $sectiondao->doGetObject( $id );
		$sectiondao->remove($condemned);
		$condemned->delete(TRUE);
		redirect( Request::prop('refurl') );
	}
	/**
	 * 
	 * No need to display anything we are moving on
	 */
	public function edit_action($id)
	{
		session_start();
		if( Request::prop('cancel') ){
			redirect( Request::prop('refurl') );
		}
		$controller = ContentLineManager::GetController( Request::prop('content_editor_type') );
		$controller->edit_action($id);
	}
	/**
	 * 
	 * No need to display anything we are moving on
	 */
	public function create_action($contentid)
	{
		session_start();
		if( Request::prop('cancel') ){
			redirect( Request::prop('refurl') );
		}
		$controller = ContentLineManager::GetController(Request::prop('content_editor_type'));
		$controller->create_action($contentid);
	}
	/***
	 * 
	 */
	public function publish( $id ){
		session_start();
		$objClass = Request::prop('content_editor_type');
		$section = new $objClass( $id );
		if( (bool)$section->publishable ){
			$section->publishable = 0;
		}
		else {
			$section->publishable = 1;
		}
		redirect( Request::prop('refurl') );
	}

}


?>